package com.jiuqi.abc.calculator.controller;

import com.jiuqi.abc.calculator.service.ABCDataValidatorService;
import com.jiuqi.abc.calculator.vo.ValidateResultVo;
import com.jiuqi.np.core.restapi.annotation.PermissionsResourceGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 龚泽楷
 * @date 2023年05月31日 20:29
 */
@Api(tags = {"数据审核结果管理"})
@RestController
@RequestMapping("abc/dataValidator")
@PermissionsResourceGroup("数据审核结果管理")
public class ABCDataValidatorController {

    @Autowired
    private ABCDataValidatorService abcDataValidatorService;

    @ApiOperation("获取审核结果")
    @GetMapping("message/{resultBeanId}")
    public Map<String, Object> getMessage(@PathVariable("resultBeanId") String resultBeanId) {
        List<ValidateResultVo> message = abcDataValidatorService.getMessage(resultBeanId);

        //返回给前端的数据
        HashMap<String, Object> result = new HashMap<>();
        result.put("message", message);
        result.put("status", "成功");

        return result;
    }

    @ApiOperation("导出")
    @PostMapping("export/{period}/{unitCode}")
    public void exportData(@PathVariable("period") String period, @PathVariable("unitCode") String unitCode, HttpServletResponse response) {
        abcDataValidatorService.processExportData(period, unitCode, response);
    }


}
